package zb.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author wzby
 * @Date: 2022/8/6 16:17
 */
public class Stream7 {
    public static void main(String[] args) {
        List<Books> ls = new ArrayList<>(List.of(
                new Books("java",19,20),
                new Books("javase",1,203),
                new Books("java++",189,10),
                new Books("javas",195,187),
                new Books("javago",193,204)));
        Stream<Books> str = ls.stream().parallel();
        //str.forEach(System.out::println);
        //ls.stream().parallel().forEach(System.out::println);

        //判断所有书籍是不是价格超过20元
        //System.out.println(str.anyMatch(e -> e.getScore()>20));
        //System.out.println(str.filter(e -> e.getScore()>20).count());
        System.out.println(str.filter(e -> e.getScore()>20).findFirst().get());

        //System.out.println(str.filter(e -> e.getScore()>20).findAny().get());

       // Stream<Integer> str= Stream.of(1,2,34,5).parallel();
        //System.out.println(str.findAny().get());

        //Optional<Books> os = ls.stream().filter(e -> e.getName().contains("java")).parallel().findAny();
        //System.out.println(os.orElse(null));

        //if (os.isPresent()) {
            //.isPresent判断查询的类对象是否存在
           // System.out.println(os.get());
        //}

    }
}
